/**
 * @name App
 * @desc 聊天室
 * @author darcrand
 * @version 2018-10-15
 */

import React, { Component, Fragment } from 'react'
import UserSignUp from '@/pages/UserSignUp'
import ChatRoom from '@/pages/ChatRoom'
import { User } from '@/utils'

const user = new User()

class App extends Component {
    constructor() {
        super()
        this.state = {
            userInfo: user.get()
        }
    }

    onSignUp = (name, avatar) => {
        console.log('user', { name, avatar })
        this.setState({ userInfo: user.set(name, avatar) })
    }

    render() {
        const { userInfo } = this.state

        return (
            <Fragment>{userInfo ? <ChatRoom userInfo={userInfo} /> : <UserSignUp onSignUp={this.onSignUp} />}</Fragment>
        )
    }
}

export default App
